package com.wnn.demo.model.hospital.controller;

import com.github.pagehelper.PageInfo;
import com.wnn.demo.domain.Hospital;

import com.wnn.demo.model.hospital.service.HospitalService;
import com.wnn.demo.pojo.Result;
import com.wnn.demo.pojo.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 医院管理
 * @author asus
 */
@RestController
@RequestMapping("/manage/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;


    @GetMapping()
    public Result selectEmployeeAll(@RequestParam(defaultValue = "1")Integer page,
                                    @RequestParam(defaultValue = "10")Integer limit){
        PageInfo< Hospital > pageInfo  = hospitalService.selectHospitalAll(page,limit);
        return new Result(ResultCode.OK,pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     *
     */
    @GetMapping("/exportHosipitalExcle")
    public Result exportHosipitalExcle(){
        hospitalService.exportHosipitalExcle();
        return new Result(ResultCode.OK);
    }


    /**
     * 得到员工界面的地区+医院树结构
     * @return
     */
    @GetMapping("/hospAndDeptTree")
    public Result findHospAndDeptMenu(){
        List< Map> list = hospitalService.findHospAndDeptMenu();
        return new Result(ResultCode.OK,list);
    }

    /**
     * 新增医院
     * @param hospital
     * @return
     */
    @PostMapping()
    public Result insertEmployee(@RequestBody Hospital hospital){
        int i = hospitalService.insertHospital(hospital);
        if (i>0){
            return Result.ok();
        }
        return Result.error();
    }

    /**
     * 更新医院
     * @param hospital
     * @return
     */
    @PutMapping("/{id}")
    public Result updateEmployee(@PathVariable(value = "id")String id,@RequestBody Hospital hospital){
        hospital.setId(id);
        int i = hospitalService.updateHospital(hospital);
        if (i>0){
            return Result.ok();
        }
        return Result.error();
    }


    /**
     * 根据医院Id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable(value = "id") String id) {
        int i = hospitalService.deleteHospitalById(id);
        if (i>0){
            return Result.ok();
        }
        return Result.error();
    }


    @PostMapping("/batchHospital")
    public Result batchHospitalByIds(String ids ) {

        int i = hospitalService.batchHospitalByIds(ids);
        if (i>0){
            return Result.ok();
        }
        return Result.error();

    }

}